package controllers

import (
	"github.com/astaxie/beego/logs"

	"lottery/models"
	"lottery/services/lottery"
)

type LotteryCtl struct {
	BaseCtl
}

func (l *LotteryCtl) Login() {
	agent := new(models.Agent)
	agent.LoginName = l.GetString("name", "")
	agent.Passwd = l.GetString("passwd", "")
	agent.PlatformId, _ = l.GetInt("type", 0)

	logs.Debug("登录信息 %+v", agent)

	lottery, ok := lottery.GetLottery(agent)
	if !ok {
		l.SetJson(&struct {
			Msg string
		}{
			Msg: "不支持该渠道",
		}, nil)
		return
	}

	actionResp := lottery.Login()
	if !actionResp.IsSuccess {
		actionResp = lottery.ReLogin()
		if actionResp.IsSuccess {
			l.SetJson(lottery.AgentInfo(), nil)
		} else {
			l.SetJson(actionResp, nil)
		}
	} else {
		l.SetJson(lottery.AgentInfo(), nil)
	}
}
